{% extends "base.html" %}
{% block title %}
    图片展示

{% endblock %}
{% block body %}
    <div class="container">
        <div class="row" style="padding-top: 10px;padding-bottom: 10px">
            <div class="col">
                <label for="exampleFormControlFile1">选择相册上传</label>
            </div>
            <form enctype="multipart/form-data" method="post" action="/auth/show/photos">
                <div class="row">

                    <div class="col">
                        <input type="file" class="form-control-file" name="photo" id="photo">
                    </div>
                    <button class="btn btn-primary">上传</button>
                </div>
            </form>
        </div>
        <div class="row">
            {% for photo in paginate.items %}
                <div class="col" style="margin-bottom: 5px;text-align: center">

                    <img src="http://se6tbmbjx.hn-bkt.clouddn.com/{{ photo.photo_name }}"
                         style="height: 200px;width: auto;"
                         alt="图片无法显示">
                    <a href="/">
                        <p>{{ photo.photo_name }}</p>
                    </a>
                    <button type="button" class="btn btn-light delete_photo" tag={{ photo.id }}>删除</button>
                </div>
            {% endfor %}

        </div>
        {# 分页 #}


        <div>
            {% if not paginate.has_prev %}
                <a class="btn btn-primary btn-lg disabled" style="background-color: #5a6268" role="button">上一页</a>
            {% else %}
                <a class="btn btn-primary btn-lg" role="button" aria-disabled="true"
                   href={{ url_for("auth.show_photos", page=paginate.page - 1) }}>上一页</a>
            {% endif %}
            {% if not paginate.has_next %}
                <a class="btn btn-primary btn-lg disabled" style="float: right;background-color: #5a6268" role="button">下一页</a>
            {% else %}
                <a class="btn btn-primary btn-lg" role="button" style="float: right"
                   href={{ url_for("auth.show_photos", page=paginate.page + 1) }}>下一页</a>
            {% endif %}
        </div>
    </div>
    <script>
        $('.delete_photo').click(
            function () {
                var id = $(this).attr("tag")
                $.post(
                    "/auth/delete/photos",
                    {"photo_id": id},
                    function (data) {
                        if (data.code == 200) {
                            alert("删除成功")
                            window.location.reload()
                        } else {
                            alert("删除失败")
                        }
                    }
                )
            }
        )

    </script>
{% endblock %}
